import Vue from 'vue';
import Vuex from 'vuex';


Vue.use(Vuex);

const myStoreModule = {
  namespaced: true,
  state: {
    unreadCount: 0,//消息
    unreadCount1:0,//审核
    unreadCount2:0,//库存
  },
  mutations: {
    updateUnreadCount(state, count) {
      state.unreadCount = count;
    },
    updateUnreadCount1(state, count) {
      state.unreadCount1 = count;
    },
    updateUnreadCount2(state, count) {
      state.unreadCount2 = count;
    }
  },
  actions: {
    checkUnreadCount({ commit }, messages) {
      const unreadCount = messages.filter(message => message.state === '1').length;
      const unreadCount1=messages.filter(message => message.state === '1' && message.type === '0' ).length;
      const unreadCount2=messages.filter(message => message.state === '1' && message.type === '3' ).length;
      commit('updateUnreadCount', unreadCount);
      commit('updateUnreadCount1', unreadCount1);
      commit('updateUnreadCount2', unreadCount2);
      if (unreadCount === 0) {
        console.log('没有未读消息');
      }
      if(unreadCount1===0){
        console.log('没有未读消息');
      }
      if(unreadCount2===0){
        console.log('没有未读消息');
      }
    }
  }
};

export default myStoreModule;
